package com.cytech.cloudclinic.contract;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import androidx.activity.result.contract.ActivityResultContract;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cytech.cloudclinic.bean.Drug;
import com.cytech.cloudclinic.moudle.main.clinic.admission.prescription.template.PrescriptionTemplateActivity;

import java.util.List;

public class PrescriptionTemplateContract extends ActivityResultContract<Integer, List<Drug>> {
    @NonNull
    @Override
    public Intent createIntent(@NonNull Context context, Integer input) {
        Intent intent = new Intent(context, PrescriptionTemplateActivity.class);
        intent.putExtra("drugParentTag",input);
        return intent;
    }

    @Override
    public List<Drug> parseResult(int resultCode, @Nullable Intent intent) {
        if(intent!=null){
            List<Drug> data = (List<Drug>) intent.getSerializableExtra("result");
            if(resultCode == Activity.RESULT_OK&&data!=null){
                return data;
            }
        }
        return null;
    }
}
